{include file="public/layout" /}
<body style="overflow: auto; cursor: default; -moz-user-select: inherit;background-color:#F4F4F4; padding: 15px; ">
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<div class="page" >
    <div class="flexigrid">
        <div class="mDiv">
            <div class="ftitle">
                <h3>分类列表</h3>
                <h5>(共{$pager->totalRows}条数据)</h5>
            </div>
            <!-- <div title="刷新数据" class="pReload"><i class="fa fa-refresh"></i></div> -->
            <form class="navbar-form form-inline" id="postForm" action="{:url('Coupon/select_arctype')}" method="get" onsubmit="layer_loading('正在处理');">
                {$searchform.hidden|default=''}
                <div class="sDiv">
                    <div class="sDiv2">
                        <input type="text" size="50" name="typename" value="{$Request.param.typename}" class="qsbox" placeholder="搜索分类名称...">
                        <input type="submit" class="btn" value="搜索">
                        <i class="fa fa-search"></i>
                    </div>
                </div>
            </form>
        </div>
        <div class="hDiv">
            <div class="hDivBox">
                <table cellspacing="0" cellpadding="0" style="width: 100%">
                    <thead>
                    <tr>
                        <th class="sign w40" axis="col0">
                            <div class="tc"><input type="checkbox" class="checkAll" onclick="AllSelect(this);"></div>
                        </th>
                        <th align="left" abbr="article_title" axis="col3" class="">
                            <div style="text-align: left; padding-left: 10px;" class="">分类名称</div>
                        </th>
                    </tr>
                    </thead>
                </table>
            </div>
        </div>
        <div class="bDiv" style="height: auto;">
            <div id="flexigrid" cellpadding="0" cellspacing="0" border="0">
                <table style="width: 100%">
                    <tbody>
                    {empty name="list"}
                        <tr>
                            <td class="no-data" align="center" axis="col0" colspan="50">
                                <i class="fa fa-exclamation-circle"></i>没有符合条件的记录
                            </td>
                        </tr>
                    {else/}
                        {volist name="list" id="vo"}
                        <tr>
                            <td class="sign">
                                <div class="w40 tc">
                                    <input type="checkbox" name="ids[]" value="{$vo.arctype_id}" onclick="Select(this);">
                                </div>
                            </td>
                            <td class="" style="width: 100%;">
                                <div class="tl" style="padding-left: 10px;">
                                    <a href="{$vo|get_typeurl=###}" target="_blank">
                                        {$vo.typename}
                                    </a>
                                </div>
                            </td>
                        </tr>
                        {/volist}
                    {/empty}
                    </tbody>
                </table>
            </div>
            <div class="iDiv" style="display: none;"></div>
        </div>
        <div class="tDiv">
            <div class="tDiv2">
                <div class="fbutton checkboxall">
                    <input type="checkbox" class="checkAll" onclick="AllSelect(this);">
                </div>
                <div class="fbutton">
                    <a onclick="SaveData();" class="layui-btn layui-btn-primary">
                        <span>选择</span>
                    </a>
                </div>
                {include file="public/page" /}
            </div>
            <div style="clear:both"></div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function(){
        $('input[name*=ids]').click(function(){
            if ($('input[name*=ids]').length == $('input[name*=ids]:checked').length) {
                $('.checkAll').prop('checked','checked');
            } else {
                $('.checkAll').prop('checked', false);
            }
        });
        $('input[type=checkbox].checkAll').click(function(){
            $('input[type=checkbox]').prop('checked',this.checked);
        });

        // 表格行点击选中切换
        $('#flexigrid > table>tbody >tr').click(function(){
            $(this).toggleClass('trSelected');
        });

        // 设置已选项
        var SelectArctypeID = parent.$('#SelectArctypeID').val();
        if (SelectArctypeID) {
            SelectArctypeID = SelectArctypeID.split(',');
            if (SelectArctypeID) {
                $('input[name*=ids]').each(function(i, o){
                    if (($.inArray($(o).val(), SelectArctypeID) >= 0)) {
                        $(o).prop('checked', 'checked');
                    }
                });
                if ($('input[name*=ids]').length == $('input[name*=ids]:checked').length) {
                    $('.checkAll').prop('checked','checked');
                } else {
                    $('.checkAll').prop('checked', false);
                }
            }
        }
    });

    // 单页单选
    function Select(obj) {
        if($(obj).is(':checked')) {
            var SelectArctypeID = parent.$('#SelectArctypeID').val();
            if (SelectArctypeID) {
                parent.$('#SelectArctypeID').val(SelectArctypeID + ',' + $(obj).val());
            } else {
                parent.$('#SelectArctypeID').val($(obj).val());
            }
        } else {
            var SelectArctypeID = parent.$('#SelectArctypeID').val();
            if (SelectArctypeID) {
                SelectArctypeID = SelectArctypeID.split(',');
                for (var i = 0; i < SelectArctypeID.length; i++) {
                    if (SelectArctypeID[i] == $(obj).val()) {
                        SelectArctypeID.splice(i, 1);
                    }
                }
                SelectArctypeID = SelectArctypeID.join(",");
                parent.$('#SelectArctypeID').val(SelectArctypeID);
            }
        }
    }

    // 选择确认数据
    function SaveData() {
        var SelectArctypeIDNew = parent.$('#SelectArctypeID').val();
        parent.$('#arctype_id').val(SelectArctypeIDNew);
        if (SelectArctypeIDNew) {
            parent.$('#arctype_id_num').html(SelectArctypeIDNew.split(",").length).parent().show();
        } else {
            parent.$('#arctype_id_num').parent().hide();
        }
        parent.layer.close(parentObj);
    }
</script>

{include file="public/footer" /}